package com.example.b_308.myapplication.view.main;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.example.b_308.myapplication.R;
import com.example.b_308.myapplication.controller.AddressController;
import com.example.b_308.myapplication.model.been.AddressBeen;
import com.example.b_308.myapplication.model.been.MessageBeen;
import com.example.b_308.myapplication.model.Staff;
import com.example.b_308.myapplication.view.base.BaseFragment;
import com.example.b_308.myapplication.view.main.Base.AddressAdapter;
import com.example.b_308.myapplication.view.main.Base.IAddressView;

import java.util.List;

/**
 * Created by B-308 on 2017/11/21.
 */
public class AddressFragment extends BaseFragment implements IAddressView, AddressAdapter.IAddressClick {
    AddressAdapter addressAdapter;
    ListView lv_address;
    List<MessageBeen> messageBeens;
    AddressController addressController;

    @Nullable
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState){
        View view = inflater.inflate(R.layout.fragment_address,null,false);
        lv_address = (ListView) view.findViewById(R.id.lv_address);
        addressController = new AddressController(this);
        addressController.getList();
        //((TextView) view.findViewById(R.id.address)).setText(getTitle());
        return view;
    }

    @Override
    protected void init() {

    }

    @Override
    protected View setContentView(LayoutInflater inflater) {
        return null;
    }


    @Override
    public void onRequestListSuccess(List<Staff> addressBeens) {
        if(null == addressAdapter){
            addressAdapter = new AddressAdapter(addressBeens,getActivity(),this);
            lv_address.setAdapter(addressAdapter);
        }else {
            addressAdapter.setList(addressBeens);
        }
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                lv_address.setAdapter(addressAdapter);
            }
        });

    }

    @Override
    public void onSearchClick() {

    }

    @Override
    public void onCustomerAddressClick() {

    }

    @Override
    public void onAddStaffClick() {

    }

    @Override
    public void onCompanydepartmentClick() {

    }

    @Override
    public void onStaffClick(Staff staff) {

    }

    @Override
    public void fail(String message) {

    }
}
